package com.atguigu01.string.exer3;

import java.util.Arrays;
import java.util.Scanner;

/**
 * ClassName: answer
 * Package: com.atguigu01.string.exer3
 * Description:
 *
 * @Author BuTang
 * @Create 2023/5/23 17:03
 * @Version 1.0
 */
public class answer {
    String[] users = new String[3];
    String name;
    String key;
    {
        users[0] = "songhk-123";
        users[1] = "Tom-8888";
        users[2] = "Jerry-6666";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void in(){
        boolean isExist = true;
        System.out.println("请输入账户名");
        Scanner sca = new Scanner(System.in);
        String myname = sca.next();

        for (int i = 0; i < users.length; i++) {
            int idex = users[i].indexOf("-");
            if (myname.equals(users[i].substring(0,idex))){


                System.out.println("请输入登录密码");

                //输入的密码
                String key1 = sca.next();
                //账户密码
                String key2 = users[i].substring(idex+1,users[i].length());

                //System.out.println(key1.equals(key2));//测试用

                if (key1.equals(key2)){
                    System.out.println("登录成功");
                } else {
                    System.out.println("密码错误");
                    break;
                }
                isExist = false;
            }
        }

        if (isExist)System.out.println("账户不存在");


    }



    @Override
    public String toString() {
        for (int i = 0; i < users.length; i++) {
            System.out.println(users[i]);
        }
        System.out.println();
               return null;
    }
}
